﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using YT.DB;
using YT.Commons;
namespace YT.XH.Dizziness
{
    public partial class frmDZTherapeuticMethodMtn : Form
    {

        private string mstrSickRecID = string.Empty;
        private DBAccess mdbcon = new DBAccess(false, false);
        private bool mblnNewPeriod = false;
        public frmDZTherapeuticMethodMtn()
        {
            InitializeComponent();
            mstrSickRecID = SysVar.SickRecID;
        }

        public frmDZTherapeuticMethodMtn(string strSickRecID)
        {
            InitializeComponent();
            mstrSickRecID = strSickRecID;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string strSQL = string.Empty;
            string strOldCaseName = DataFunctions.GetFieldValue ( "mSickPerson","CurOperation","SickRecID='"+ mstrSickRecID +"'");
            strSQL = "update mSickPerson set CurOperation='" + GetOperationNameFromRad() + "' where sickrecid='" + mstrSickRecID + "'";
            mdbcon.ExecuteSql(strSQL);
            string strTreatCaseName = GetOperationNameFromRad ();

            if ( strOldCaseName != strTreatCaseName )
            {
                int intPeriod =CvtFunc.ToInt  ( DataFunctions.GetFieldValue ( "mTreatHistory","Period","SickRecID='"+ mstrSickRecID  +"'"));
                intPeriod++;
                
                strSQL = " INSERT INTO mTreatHistory (SickRecID, TreatCaseName,Period  ) "
                        + " VALUES ( '" + mstrSickRecID + "', '" + strTreatCaseName  + "', '" + intPeriod + "' ) ";
                mdbcon.ExecuteSql(strSQL);
            }
            this.Close();
        }

        private void FillCurOperation()
        {
            string strSQL = "select * from mSickPerson where sickrecid='" + mstrSickRecID + "'";
            DataRow drRow = mdbcon.GetDataFirstRow(strSQL);
            if (drRow == null) return;

            GetRadFromOperationName(CvtFunc.ToString(drRow["CurOperation"]));

        }

        private string GetOperationNameFromRad()
        {
            if (rad方案1.Checked) return "方案1";
            if (rad方案2.Checked) return "方案2";

            if (radA1.Checked) return "方案A1";
            if (radA2.Checked) return "方案A2";
            if (radA3.Checked) return "方案A3";
            if (radA4.Checked) return "方案A4";

            if (radB1.Checked) return "方案B1";
            if (radB2.Checked) return "方案B2";

            if (radC1.Checked) return "方案C1";
            if (radC2.Checked) return "方案C2";


            return "";
        }

        private void GetRadFromOperationName(string strOperationName)
        {
            if (strOperationName == "方案1") rad方案1.Checked = true;
            if (strOperationName == "方案2") rad方案2.Checked = true;

            if (strOperationName == "方案A1") radA1.Checked = true;
            if (strOperationName == "方案A2") radA2.Checked = true;
            if (strOperationName == "方案A3") radA3.Checked = true;
            if (strOperationName == "方案A4") radA4.Checked = true;

            if (strOperationName == "方案B1") radB1.Checked = true;
            if (strOperationName == "方案B2") radB2.Checked = true;

            if (strOperationName == "方案C1") radC1.Checked = true;
            if (strOperationName == "方案C2") radC2.Checked = true;
        }
        
        private void frmDZTherapeuticMethodMtn_Load(object sender, EventArgs e)
        {
            this.Text = "治疗方案";
            FillCurOperation();
            this.Width = 700;
            this.Height = 500;            
            timer1.Start();
        }

        private void btnContraindication_Click(object sender, EventArgs e)
        {
            frmDZMethodMtn frmMethodMtn = new frmDZMethodMtn();
            //frmMethodMtn.MdiParent = SysVar.mfrmMdiPar;
            frmMethodMtn.ShowDialog(); 
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close(); 
        }

        private void frmDZTherapeuticMethodMtn_FormClosed(object sender, FormClosedEventArgs e)
        {
            SysVar.marrFormList.Remove(this.Name);
        }

        private void btnNext_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Opacity >= 1)
                timer1.Stop();
            this.Opacity += 0.04;
        }

       
    }
}
